﻿using System;
using System.Data;
using System.Windows.Forms;
using AMS.Inventory.PDA.Core.DataAccess;

namespace AMS.Inventory.PDA
{
    public partial class FrmDeleteRepeatInfo : Form
    {
        private readonly DataTable _repeatInfoDt;
        private readonly CoreDataAccess _coreDateAssess = new CoreDataAccess();

        public FrmDeleteRepeatInfo()
        {
            InitializeComponent();
        }

        public FrmDeleteRepeatInfo(DataTable repeatInfoDt)
        {
            _repeatInfoDt = repeatInfoDt;
            InitializeComponent();
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void BtnSelect_Click(object sender, EventArgs e)
        {
            DataRow reaperRow = null;
            string barcode = "", assetName = "";
            if (DgrdRepeatInfo.CurrentRowIndex < 0)
            {
               // MessageBox.Show(c);
                return;
            }
            reaperRow = _repeatInfoDt.Rows[DgrdRepeatInfo.CurrentCell.RowNumber];
            barcode = reaperRow[""].ToString();
            assetName = reaperRow[""].ToString();
            int factRow = 0;
            factRow = _coreDateAssess.DeleteAssetsByCode(barcode, assetName);
            if (factRow > 0)
            {
                _repeatInfoDt.Rows.Remove(reaperRow);
                _repeatInfoDt.Reset();
            }
        }

        private void FrmDeleteRepeatInfo_Load(object sender, EventArgs e)
        {
            string columnsTitle = "Id,数据唯一标识;setTypeInfo,资产类别信息;TypeName,资产类型别名;Barcode,资产条形码;" +
                            "CheckDate,盘点日期 ;DepartmentInfo,所属部门;Location,详细位置;Manufacturers,制造商;Memo,备注;ModelNumber,规格型号;" +
                            "Name,名称;NatureInfo,资产性质;ParentBarcode,父资产条形码;SerialNumber,出厂编号;ShelfLife,保质期;SiteInfo,地点 ;SourceInfo,资产来源;" +
                            "StartUpDate,启用时间;StateInfo,状态;Supplier,供应商;UnitInfo,单位;UseYears,使用年限;InitDate,初始化时间";
           
            CoreDataAccess.SetColumnsTitle(columnsTitle,_repeatInfoDt,this.DgrdRepeatInfo);
            
        }
    }
}